var mongoose = require('mongoose');
//var Promise = require('bluebird');
console.log('建立mongoose连接..');
//mongoose.Promise = Promise;
//var options = {  
//  server: {
//      auto_reconnect: true,
//      poolSize: 10,
//  }
//};

var options = {  

        auto_reconnect: true,
        poolSize: 10,
    
};

// {useMongoClient:true}
//定义一个数据库地址，创建一个dong数据库
//Promise.promisifyAll(mongoose);
var dbURL = 'mongodb://101.132.35.248/user';

mongoose.connect(dbURL,options);

mongoose.connection.on('connected',function  () {
    console.log('mongoose default connection open to :'+dbURL);
});

mongoose.connection.on('error',function  (error) {
    console.log('mongoose连接错误 :'+error);
});

mongoose.connection.on('disconnected',function  () {
    console.log('mongoose 没有连接上');
});

//if the node process ends ，close the mongoose connection

process.on('SIGNIT',function  () {
     
       mongoose.connection.close(function  () {
           console.log('mongoose default connection disconnected')
           process.exit(0)
       })

           


})

module.exports = mongoose;


